//
//  ForumViewController.m
//  穷游
//
//  Created by lanou3g on 15/12/17.
//  Copyright © 2015年 王忠奎. All rights reserved.
//

#import "ForumViewController.h"
#import "comView.h"
#import "comDataHandle.h"
#import "comTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "comModel.h"
@interface ForumViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,strong)comView *commView;
//接收block传过来的数组,即装每个model信息的数组
@property(nonatomic,strong)NSMutableArray *arr;

@end

@implementation ForumViewController

-(void)loadView
{

    self.commView = [[comView alloc]initWithFrame:[UIScreen mainScreen].bounds];
    self.view = self.commView;
    

}

- (void)viewDidLoad {
    [super viewDidLoad];
  
    self.navigationItem.title = @"热门帖子";
    
    //设置代理
    self.commView.tableView.dataSource = self;
    self.commView.tableView.delegate = self;
    
    //注册xib
    [self.commView.tableView registerNib:[UINib nibWithNibName:@"comTableViewCell" bundle:nil] forCellReuseIdentifier:@"comTableViewCell"];
    
    
    [[comDataHandle sharedComDataHandle]getComDataFromNet:^(id isFinished) {
        self.arr = (NSMutableArray *)isFinished;
        
        [self.commView.tableView reloadData];
    }];
    
    
    
}

#pragma mark ---实现代理方法
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{

    return 8;

}

#pragma mark ---设置分组
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{

    if (section == 0) {
        return @"穷游亚洲";
    }else if(section == 1){
        return @"穷游欧洲";
    }else if (section == 2){
        return @"穷游美洲";
    }else if (section == 3){
        return @"穷游大洋洲";
    }else if (section == 4){
        return @"穷游非洲";
    }else if (section == 5){
        return @"穷游兴趣小组";
    }else if (section == 6){
        return @"线上线下";
    }else
        return @"后院";


}

//- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
//    
//    NSString *HeaderString = nil;
//    
//    switch (section) {
//        case 0:
//            HeaderString = [NSString stringWithFormat:@"Header Text 1"];
//            break;
//        case 1:
//            HeaderString= [NSString stringWithFormat:@"Header Text 2"];
//            break;
//        case 2:
//            HeaderString = [NSString stringWithFormat:@"Header Text 3"];
//            break;
//    }
//    UILabel *HeaderLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 40)];
//    HeaderLabel.backgroundColor = [UIColor clearColor];
//    HeaderLabel.font = [UIFont boldSystemFontOfSize:18];
//    HeaderLabel.textColor = [UIColor whiteColor];
//    HeaderLabel.text = HeaderString;
//    return HeaderLabel;
//}

#pragma mark ---设置分组高度
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{

    return 40;
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

//    NSMutableArray *arr0 = [NSMutableArray array];
//    NSMutableArray *arr1 = [NSMutableArray array];
//    NSMutableArray *arr2 = [NSMutableArray array];
//    NSMutableArray *arr3 = [NSMutableArray array];
//    NSMutableArray *arr4 = [NSMutableArray array];
//    NSMutableArray *arr5 = [NSMutableArray array];
//    NSMutableArray *arr6 = [NSMutableArray array];
//    NSMutableArray *arr7 = [NSMutableArray array];
//    for (int i = 0; i<80; i++) {
//        if (i>=0 && i<=27) {
//            [arr0 addObject:self.arr[i]];
//        }else if (i>27 && i<=45){
//            [arr1 addObject:self.arr[i]];
//        }else if (i>45 && i<=49){
//            [arr2 addObject:self.arr[i]];
//        }else if (i>49 && i<=52){
//            [arr3 addObject:self.arr[i]];
//        }else if (i>52 && i<=56){
//            [arr4 addObject:self.arr[i]];
//        }else if (i>56 && i<=72){
//            [arr5 addObject:self.arr[i]];
//        }else if (i>72 && i<=76){
//            [arr6 addObject:self.arr[i]];
//        }else
//            [arr7 addObject:self.arr[i]];
//    }
    
            if (section == 0) {
                return 27;
            }else if(section == 1){
                return 18;
            }else if (section == 2){
                return 4;
            }else if (section == 3){
                return 3;
            }else if (section == 4){
                return 4;
            }else if (section == 5){
                return 16;
            }else if (section == 6){
                return 4;
            }else
                return 3;
//            return [comDataHandle sharedComDataHandle].comDataArray.count/2;
    
        
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    comTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"comTableViewCell"];
    comModel *model = self.arr[indexPath.row*2];
    comModel *model1 = self.arr[indexPath.row*2+1];
    NSLog(@"=====%@",model);
//
    
    
    [cell setCellDataWithModel:model withModel:model1];
    
//        [cell.photoImage2 sd_setImageWithURL:[NSURL URLWithString:model1.photo]];
//        cell.nameLabel2.text = model1.name1;
//        cell.totalLabel2.text = model1.total_threads;
//        [cell.photoImage1 sd_setImageWithURL:[NSURL URLWithString:model1.photo]];
//        cell.nameLabel1.text = model1.name1;
//        cell.totalLabel1.text = model1.total_threads;
    return cell;

}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

    return 70;
    

}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    [tableView deselectRowAtIndexPath:indexPath animated:YES];



}





/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
